package com.stylefeng.guns.core.config;

import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author carloszhang
 */
@Configuration
public class OkHttpClientConfig {

    private static final int DEFAULT_CONNECTION_TIMEOUT_IN_MS = 15000;

    private static final int DEFAULT_SOCKET_TIMEOUT_IN_MS = 20000;

    @Bean(name = "buildOkHttpClient")
    OkHttpClient buildOkHttpClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(DEFAULT_CONNECTION_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS)
                .readTimeout(DEFAULT_SOCKET_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS)
                .build();
    }
}
